<template>
  <div>
<van-button
            class="follow-btn"
            type="info"
            color="#3296fa"
            round
            size="small"
            icon="plus"
            v-if='!isFollowed'
            @click="onFollowed"
            :loading='isFollowLoading'
          >关注</van-button>
          <van-button
          v-else
          @click="onFollowed"
           :loading='isFollowLoading'
            class="follow-btn"
            round
            size="small"
          >已关注</van-button>
  </div>
</template>

<script>
import { deleteFollowed, followedUser } from '@/api/user.js'

export default {
  props: {
    isFollowed: {
      type: Boolean,
      require: true
    },
    autId: {
      type: [String, Number, Object],
      require: true
    }
  },
  data () {
    return {
      isFollowLoading: false

    }
  },
  model: {
    prop: 'isFollowed',
    event: 'updataFollowed'
  },
  created () {

  },

  methods: {
  // 是否关注该作者
    async    onFollowed () {
      this.isFollowLoading = true
      try {
        if (this.isFollowed) {
        // 处于已关注 要做取消关注
          await deleteFollowed(this.autId)
        } else {
        // 处于未关注 要做关注
          await followedUser(this.autId)
        }
        this.$emit('updataFollowed', !this.isFollowed)
        // this.articles.is_followed = !this.articles.is_followed
        this.isFollowLoading = false
      } catch (err) {
        console.log(err)
      }
    }
  }
}
</script>

<style scoped lang='less'>
.follow-btn {
        width: 170px;
        height: 58px;
      }
</style>
